import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);
const originalPush = Router.prototype.push

Router.prototype.push = function push(location) {

  return originalPush.call(this, location).catch(err => err)

}
const routes = [
  {
    path: '*',
    redirect: '/index'
  },
  {
    name: 'user',
    component: () => import('./view/user'),
    meta: {
      // title: '会员中心'
    }
  },
  {
    name: 'De',
    path: "/De",
    component: () => import('./view/De'),
    meta: {
      // title: '购物车'
    }
  },
  {
    path: "/classList/:id",
    component: () => import('@/view/classList'),
    meta: {
      // title: '购物车'
    }
  },
  {
    path: "/des/:index/:combinationindex",
    component: () => import('@/view/des'),
    meta: {
      // title: '购物车'
    }
  },
  {
    name: 'index',
    component: () => import('@/view/index'),
    meta: {
      // title: '商品详情'
    }
  }
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});





export {
  router
};
